﻿using AForge.Video.DirectShow;
using Clancy.Common;
using Clancy.Data;
using Clancy.Interfaces;
using System.Collections.Generic;

namespace Clancy.Bl.VideoProvider
{
    internal class VideoSourceProvider : IVideoSourceProvider
    {
        private List<IVideoSourceFilterInfo> m_AvailableVideoSources;

        public IEnumerable<IVideoSourceFilterInfo> GetVideoSources()
        {
            if (m_AvailableVideoSources == null)
            {
                m_AvailableVideoSources = new List<IVideoSourceFilterInfo>();
                foreach (FilterInfo filterInfo in new FilterInfoCollection(FilterCategory.VideoInputDevice))
                {
                    m_AvailableVideoSources.Add(new VideoSourceFilterInfo(filterInfo.Name, filterInfo.MonikerString));
                }

                foreach (string fixedSourceName in Constants.FixedInputSourceNames)
                {
                    m_AvailableVideoSources.Add(new VideoSourceFilterInfo(fixedSourceName, GetMonikerForFixedInputSource(fixedSourceName)));
                }
            }
            return m_AvailableVideoSources;
        }

        private static string GetMonikerForFixedInputSource(string fixedSourceName)
        {
            string moniker = string.Empty;
            switch (fixedSourceName)
            {
                case Constants.MjepSourceName:
                    moniker = Constants.MjepSourceMoniker;
                    break;

                case Constants.FileSourceName:
                    moniker = Constants.FileSourceMoniker;
                    break;
            }
            return moniker;
        }
    }
}